package com.bweab.dao.impl;

import com.bweab.dao.api.UserDepositDormitoryEnDAOInterface;
import com.bweab.dao.base.BaseDao;
import com.bweab.pojo.en.UserDepositDormitoryEn;

import java.util.List;

/**
 * 该类用于三表查询
 * users_tb   deposit_tb   dormitory_tb
 *
 */
public class UserDepositDormitoryEnDaoImpl extends BaseDao<UserDepositDormitoryEn> implements UserDepositDormitoryEnDAOInterface {

    @Override
    public List<UserDepositDormitoryEn> getUserDepositDormitryAll(int userId, int page, int pageSize) {
        //int start;
        int start;

        //准备多表查询的语句
        String sql="select\n" +
                "    (select count(*) from deposit_tb dpt where dpt.user_id=?) totalCount,\n" +
                "    dpt.user_id userId,\n" +
                "    urs.user_name userName,\n" +
                "    dpt.deposit_monkey depositMonkey,\n" +
                "    dmy.dormitory_name dormitoryName,\n" +
                "    dpt.deposit_time depositTime\n" +
                "\n" +
                "from deposit_tb dpt left join dormitory_tb dmy on(dpt.dormitory_id = dmy.dormitory_id)\n" +
                "                    left join users_tb urs on(urs.user_id = dpt.user_id)\n" +
                "\n" +
                "where dpt.user_id=?\n" +
                "\n" +
                "limit ?,?";

        //所取元素的起始位置
        if(page==1){
            start=0;
        }else {
             start = (page-1)  * pageSize;
            //所取元素的结束位置  pageSize

        }



        //返回三表查询的实体集合
        List<UserDepositDormitoryEn> userDepositDormitoryEnList = queryList(sql, UserDepositDormitoryEn.class, userId, userId, start, pageSize);
        return userDepositDormitoryEnList;
    }
}
